package com.boyinet.demo.pipelineleakage.controller;

import com.boyinet.demo.pipelineleakage.bean.primary.SchedulerJob;
import com.boyinet.demo.pipelineleakage.common.R;
import com.boyinet.demo.pipelineleakage.service.SchedulerJobService;
import com.boyinet.demo.pipelineleakage.vo.SchedulerJobVo;
import org.quartz.SchedulerException;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("schedulerJob")
public class SchedulerJobController {

    private final SchedulerJobService schedulerJobService;

    public SchedulerJobController(SchedulerJobService schedulerJobService) {
        this.schedulerJobService = schedulerJobService;
    }

    @CrossOrigin
    @RequestMapping(value = "list",method = RequestMethod.GET)
    R<List<SchedulerJob>> list(Integer page, Integer limit) {
        PageRequest pageRequest = PageRequest.of(page - 1, limit);
        return schedulerJobService.findAll(pageRequest);
    }

    @RequestMapping("save")
    R<Void> save(SchedulerJobVo vo) throws SchedulerException {
        schedulerJobService.save(vo);
        return R.ok("新增成功");
    }

    @RequestMapping("update")
    R<Void> update(SchedulerJobVo vo) throws SchedulerException {
        schedulerJobService.update(vo);
        return R.ok("更新成功");
    }

    @RequestMapping("delete")
    R<Void> delete(SchedulerJobVo vo) {
        schedulerJobService.delete(vo);
        return R.ok("删除成功");
    }

    @RequestMapping("deleteBacth")
    R<Void> deleteBatch(List<SchedulerJobVo> vos) {
        schedulerJobService.deleteBatch(vos);
        return R.ok("删除成功");
    }
}
